package cn.wildfire.chat.app.extendsion.classes;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

import cn.wildfirechat.model.GroupMember;

/**
 * Create by HEKE, 2019/8/27 10:35
 * TODO 由于集成的IM通讯框架不支持后台定义群组成员部分属性，转而使用后台人员从数据库中取出群员信息方式取代。
 * 字段不同，需要建立此对象进行转接。
 */
public class ApiGroupMember implements Parcelable {

    private String id;
    private String uuid;
    private String userName;
    private String type;
    private String groupName;
    private String joinTime;
    private String dt;
    private String silence;

    public ApiGroupMember() {
        super();
    }

    protected ApiGroupMember(Parcel in) {
        id = in.readString();
        uuid = in.readString();
        userName = in.readString();
        type = in.readString();
        groupName = in.readString();
        joinTime = in.readString();
        dt = in.readString();
        silence = in.readString();
    }

    /**
     * 转换为群组信息对象
     *
     * @param groupId
     * @return
     */
    public GroupMember exchange(String groupId) {
        GroupMember groupMember = new GroupMember();
        groupMember.type = GroupMember.GroupMemberType.type2(Integer.parseInt(type));
        groupMember.memberId = uuid;
        groupMember.alias = userName;
        groupMember.groupId = groupId;
        groupMember.updateDt = Long.parseLong(dt);
        groupMember.silence = Integer.parseInt(silence);
        return groupMember;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(id);
        dest.writeString(uuid);
        dest.writeString(userName);
        dest.writeString(type);
        dest.writeString(groupName);
        dest.writeString(joinTime);
        dest.writeString(dt);
        dest.writeString(silence);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<ApiGroupMember> CREATOR = new Creator<ApiGroupMember>() {
        @Override
        public ApiGroupMember createFromParcel(Parcel in) {
            return new ApiGroupMember(in);
        }

        @Override
        public ApiGroupMember[] newArray(int size) {
            return new ApiGroupMember[size];
        }
    };

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public String getJoinTime() {
        return joinTime;
    }

    public void setJoinTime(String joinTime) {
        this.joinTime = joinTime;
    }

    public String getDt() {
        return dt;
    }

    public void setDt(String dt) {
        this.dt = dt;
    }

    public String getSilence() {
        return silence;
    }

    public void setSilence(String silence) {
        this.silence = silence;
    }

    @NonNull
    @Override
    public String toString() {
        return id + "," + uuid + "," + userName + "," + type + "," + groupName + "," + joinTime + "," + dt + "," + silence;
    }

}
